package server;

public interface IClusterManagementModule extends Runnable{
	
	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run();
	
//--------------------------------------------------------------------------------------------
// Server Application Interface
//--------------------------------------------------------------------------------------------
	
	/**
	 * This method is used by the SA to inform the CMM of a new task.
	 * 
	 * @param Context - The Context of the new task
	 * @return
	 * @throws CMMExn_ClusterErr 
	 */
	public void NewTask(SATaskContext Context) throws CMMExn_ClusterErr;
	
	/**
	 * This method is used by the SA to update the CMM of a context of an existing task.
	 * 
	 * @param TaskID - The Task ID
	 * @param ContextChange - Incramental change data of the task's context
	 * @throws CMMExn_TaskErr 
	 * @throws CMMExn_ClusterErr 
	 */
	public void TaskContextUpdate(Integer TaskID, SAIncramentalTaskContext ContextChange) throws CMMExn_TaskErr, CMMExn_ClusterErr;
	
	/**
	 * This method is used by the SA to inform the CMM that it has finished servicing 
	 * an existing task.
	 * 
	 * @param TaskID
	 * @throws CMMExn_TaskErr 
	 * @throws CMMExn_ClusterErr 
	 */
	public void TaskFinish(Integer TaskID) throws CMMExn_TaskErr, CMMExn_ClusterErr;
	
	/**
	 * This method is used by the SA to close the CMM Spread connection to the cluster,
	 * and to terminate all CMM threads.
	 * 
	 * @throws CMMExn_ClusterErr 
	 * 
	 */
	public void Close() throws CMMExn_ClusterErr;
	
//	--------------------------------------------------------------------------------------------
//	 Proxy Interface
//	--------------------------------------------------------------------------------------------	
	
	/**
	 * This method is used by the ProxyServer thread to query the least busy server 
	 * in the cluster.
	 * 
	 * @return
	 */
	public ConnectionInformation FindLeastBusyServer();
	
//	--------------------------------------------------------------------------------------------
//	 AdvancedSpreadListener Interface
//	--------------------------------------------------------------------------------------------	

	/**
	 * This method is used by the AdvancedSpreadListener whenever a "New Task" message arives.
	 * 
	 * @param MachineID
	 * @param Context
	 */
	public void RecieveNewTask(Integer MachineID, TaskContext Context);
	
//	--------------------------------------------------------------------------------------------	

	/**
	 * This method is used by the AdvancedSpreadListener whenever a "Update Task" message arives.
	 * 
	 * @param MachineID
	 * @param TaskID
	 * @param ContextUpdate
	 */
	public void RecieveUpdateTask(Integer MachineID, Integer TaskID, SAIncramentalTaskContext ContextUpdate);

//	--------------------------------------------------------------------------------------------
	
	/**
	 * This method is used by the AdvancedSpreadListener whenever a "Terminate Task" message arives.
	 * 
	 * @param MachineID
	 * @param TaskID
	 */
	public void RecieveTerminateTask(Integer MachineID, Integer TaskID);

//	--------------------------------------------------------------------------------------------
	
	/**
	 * This method is used by the AdvancedSpreadListener whenever a "New Server Ready" message arives.
	 * 
	 * @param MachineID
	 */
	public void RecieveNewServerReady(Integer MachineID);
	
//	--------------------------------------------------------------------------------------------
	
	/**
	 * This method is used by the AdvancedSpreadListener whenever it recieves an unsupported message.
	 */
	public void RecieveUnsupportedMessage();
	
}
